uniform float progress;
uniform vec2 yBoundingBox;
attribute vec3 toPosition;
attribute float speed;
attribute float scale;
attribute vec3 color;
attribute vec3 toColor;
varying vec3 vColor;

void main() {

    vec3 dis = toPosition - position;
    vec3 disColor = toColor - color;

    float percent = progress / speed;
    vec3 pos;
    if(percent <= 1.) {
        pos = position + dis * percent;
        vColor = color + disColor * percent;

        float yPercent = (toPosition.y - yBoundingBox.x) / (yBoundingBox.y - yBoundingBox.x);

        if(yPercent < percent) {
            pos = toPosition;
            vColor = toColor;
        }

    } else {
        vColor = toColor;
        pos = toPosition;
    }

    vec4 viewPosition = modelViewMatrix * vec4(pos, 1.0);
    gl_Position = projectionMatrix * viewPosition;
    gl_PointSize = scale;
    gl_PointSize *= 200. / -(modelViewMatrix * vec4(pos, 1.0)).z;
}